package PL.practica1;

import java.util.ArrayList;

public class Body {

//	private String par;
	ArrayList<String> par;
	private String emph;
	private String cadena;
	
	public Body() {
		par = new ArrayList<String>();
		emph = "";
		cadena = "";
	}
	
	
	public String getPar(int i) {
		return par.get(i);
	}
	public void setPar(ArrayList<String> par) {
		this.par = par;
	}
	
	public String getEmph() {
		return emph;
	}
	public void setEmph(String emph) {
		this.emph = emph;
	}
	
	public String getCadena() {
		return cadena;
	}
	public void setCadena(String cadena) {
		this.cadena = cadena;
	}
	
	
	public void rellenarBody (String texto) {
		setCadena(texto);
		String aux = new String(getCadena());
//		System.out.println(aux);
		int j = aux.indexOf("<par>");
		boolean condicion = true;
		while (condicion == true) {
			par.add(buscarEtiqueta(aux, "<par>", "</par>"));
			aux = aux.replaceFirst("<par>", "");
			aux = aux.replaceFirst("</par>", "");
			j = aux.indexOf("<par>");
			if (j == (-1))
				condicion = false;
		}
	}
	
	
	public String buscarEtiqueta (String cadena, String etiquetaIni, String etiquetaFin) {
		
		int ini = cadena.indexOf(etiquetaIni);
		int fin = cadena.indexOf(etiquetaFin);
		
		return cadena.substring(ini, fin).replaceFirst(etiquetaIni, "");
	}
	
	
	public String translatePar() {
		String parrafo = "";
		String linea = "";
		int i = 0;
//		System.out.println(par.size());
		while (i < par.size()) {
//			System.out.println(i);
			linea = getPar(i);
			linea = linea.replace("<emph>", "<EM><span style=\"color: black;\">");
			linea = linea.replace("</emph>", "</EM>");
			parrafo += "<P><span style=\"color: 19F028;\">"+linea+"</P>\n";
			i++;
		}
		return parrafo;
	}
	
}
